<template>
  <div class="page-container">
    <SearchPanel @change="handleSearchPanelChange">
    <el-form
      ref="queryForm"
      class="query-more-form"
      size="mini"
      label-width="100px"
      :model="query"
    >
      <el-row :gutter="21">
        <el-col :span="6">
          <el-form-item label="主体名称">
            <el-input
              v-model="query.unitName"
              class="search-ipt"
              placeholder="请输入主体名称"
              maxlength="255"
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="主体类型">
            <el-select
              class="w-100"
              v-model="query.type"
              placeholder="请选择主体类型"
              clearable
            >
              <el-option
                v-for="item in department"
                :key="item.id"
                :value="item.id"
                :label="item.label"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="证件号码">
            <el-input
              v-model="query.businessCard"
              class="search-ipt"
              placeholder="请输入证件号码"
              maxlength="255"
            />
          </el-form-item>
        </el-col>
        <el-col :span="4" class="btn-col">
          <el-button size="mini" class="search-btn" @click="select">查询</el-button>
        </el-col>
      </el-row>
    </el-form>
    </SearchPanel>
    <div class="table-container">
      <div class="table-tools-panel table-flex-row">
        <el-button class="flush-btn" size="mini" icon="el-icon-refresh"
          >刷新</el-button
        >
        <div>
          <el-button
            class="tools-btn"
            size="mini"
            icon="el-icon-set-up"
          ></el-button>
          <el-button
            class="tools-btn"
            size="mini"
            icon="el-icon-share"
          ></el-button>
          <el-button
            class="tools-btn"
            size="mini"
            icon="el-icon-printer"
          ></el-button>
        </div>
      </div>
      <div class="table-list-panel">
        <el-table
          v-loading="tableLoading"
          border
          size="small"
          :data="tableData"
          :height="isShow ? 'calc(100vh - 410px)' : 'calc(100vh - 335px)'"
          style="width: 100%"
        >
          <el-table-column type="selection" width="45" />
          <el-table-column prop="unitName" label="主体名称" show-overflow-tooltip />
          <el-table-column prop="type" label="主体类型" show-overflow-tooltip>
            <template slot-scope="scope">
              <span v-show="scope.row.type === '1'">法人</span>
              <span v-show="scope.row.type === '2'">个人</span>
            </template>
          </el-table-column>
          <el-table-column prop="businessCard" label="证件号码" show-overflow-tooltip />
          <el-table-column prop="patrolCount" label="巡检次数" show-overflow-tooltip />
          <el-table-column prop="itemCount" label="违法事项数量" show-overflow-tooltip />
        </el-table>
      </div>
      <div class="pagination-panel">
        <Pagination
          :total="query.total"
          :page.sync="query.pageNum"
          :limit.sync="query.pageSize"
          @pagination="select"
        />
      </div>
    </div>
  </div>
</template>

<script>
import SearchPanel from "@/components/SearchPanel";
import Pagination from "@/components/Pagination";
import { getUnitList } from "@/api/system/doubleRandomMatters";

export default {
  name: "CaseDealDispatch",
  components: {
    SearchPanel,
    Pagination,
  },
  data() {
    return {
      query: {
        total: 0,
        pageNum: 1,
        pageSize: 10,
        type: null,
        unitName: '',
        businessCard: ''
      },
      tableLoading: false,
      tableData: [],
      department: [
        { id: 1, label: '法人' },
        { id: 2, label: '个人' }
      ],
      isShow: true,
    };
  },
  created() {
    this.initData()
  },
  methods: {
    handleSearchPanelChange(flag) {
      this.isShow = flag;
    },
    initData() {
      this.select();
    },
    select() {
      const query = JSON.parse(JSON.stringify(this.query))
      getUnitList(query)
        .then((result) => {
          this.tableLoading = false;
          this.query.total = result.total;
          this.tableData = result.rows;
        })
        .catch(() => {
          this.tableLoading = false;
        });
    },
  },
};
</script>

<style lang="scss" scoped>
</style>
